<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('采购订单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>支付方式：</label>
                            <select name="payMethod" th:with="type=${@dict.getType('purchase_pay_method')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li>
                            <label>订单状态：</label>
                            <select name="orderStatus" th:with="type=${@dict.getType('purchase_order_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li class="select-time">
                            <label style="width: 105px;">申请时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            <label style="width: 105px;">关键字查询字段：</label>
                            <select name="fields">
                                <option value="phone" selected>用户手机号</option>
                                <option value="address">地址</option>
                                <option value="trueName">用户姓名</option>
                                <option value="expressName">快递商</option>
                                <option value="expressNumber">快递单号</option>
                            </select>
                            <input type="text" name="keywords"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--<a class="btn btn-info" id="expandAllBtn">-->
            <!--<i class="fa fa-exchange"></i> 展开/折叠-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:purchase:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:purchase:remove')}]];

    var toDeliveryFlag = [[${@permission.hasPermi('system:purchase:toDelivery')}]];

    var payMethodDatas = [[${@dict.getType('purchase_pay_method')}]];
    var prefix = ctx + "system/purchase";

    var orderStatusDatas = [[${@dict.getType('purchase_order_status')}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "采购订单",
            detailView: true,
            onExpandRow: function (index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'partnerName',
                    title: '合作商'
                },
                {
                    field: 'trueName',
                    title: '姓名'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },
                {
                    field: 'id',
                    title: '商户订单号'
                },
                {
                    field: 'payTime',
                    title: '支付成功时间'
                },
                {
                    field: 'payMethod',
                    title: '支付方式',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(payMethodDatas, value);
                    }
                },
                {
                    field: 'totalAmount',
                    title: '订单总价格'
                },
                {
                    field: 'realPayAmount',
                    title: '实际支付总价格'
                },
                {
                    field: 'postAmount',
                    title: '邮费'
                },
                {
                    field: 'address',
                    title: '收件地址'
                },
                {
                    field: 'discountAmount',
                    title: '优惠价格'
                },
                {
                    field: 'createdTime',
                    title: '订单创建时间'
                },
                {
                    field: 'orderStatus',
                    title: '订单状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderStatusDatas, value);
                    }
                },
                {
                    field: 'expressName',
                    title: '快递商'
                },
                {
                    field: 'expressNumber',
                    title: '快递单号'
                },
                {
                    field: 'deliverTime',
                    title: '发货时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];

                        // 订单状态  1 待发货  2 已发货  0已取消
                        if (row.orderStatus == 1) {
                            // 待发货状态
                            actions.push('<a class="btn btn-success btn-xs ' + toDeliveryFlag + '" href="javascript:void(0)" onclick="toDelivery(\'' + row.id + '\')"><i class="fa fa-edit"></i>发货</a> ');
                        }

                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    // 跳转到发货页面
    function toDelivery(id) {
        var url = prefix + "/toDelivery/" + id;
        $.modal.open("发货操作", url, 800, 600);
    }

    initChildTable = function (index, row, $detail) {
        // 展示详情
        var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
        $(childTable).bootstrapTable({
            url: prefix + "/itemslist",
            method: 'post',
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            queryParams: {
                purchaseId: row.id
            },
            columns: [
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'itemImg',
                    title: '商品图片',
                    formatter: function (value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'itemName',
                    title: '商品名称'
                },
                {
                    field: 'buyCounts',
                    title: '购买数量'
                },
                {
                    field: 'price',
                    title: '成交价格'
                },
            ]
        });
    };

</script>
</body>
</html>